package com.un.ebs.sys.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.un.ebs.sys.domain.UserWx;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author liubo
 * @since 2020-03-07
 */
@Component
public interface UserWxMapper extends BaseMapper<UserWx> {

    @SqlParser(filter = true)
    @Select("select top 1 * from sys_user_wx where open_id=#{id}")
    UserWx queryByOpenId(@Param("id") String id);

    @SqlParser(filter = true)
    @Select("select top 1 * from sys_user_wx where user_id=#{userId} and tenant_id=#{tenantId}")
    UserWx queryByUserIdAndTenantId(@Param("userId") String userId, @Param("tenantId") String tenantId);

    @SqlParser(filter = true)
    @Select("select top 1 * from sys_user_wx where open_id=#{openId} and tenant_id=#{tenantId}")
    UserWx queryByOpenIdAndTeantId(@Param("openId") String openId, @Param("tenantId") String tenantId);

    @Select("SELECT TOP 1 open_id FROM sys_user_wx WHERE user_id=#{userId} AND tenant_id IN (SELECT id FROM dbo.sys_app_tenant WHERE ent_id=#{entId})")
    String queryOpenIdByUserIdAndEntId(@Param("userId") String userId, @Param("entId") String entId);

}
